<template>
  <div class="profile-page">
    <div class="container">
      <div class="profile-header">
        <div class="profile-avatar">
          <img src="https://picsum.photos/seed/profile/200/200" alt="头像">
        </div>
        <div class="profile-info">
          <h1 class="profile-name">张三</h1>
          <p class="profile-title">前端开发工程师</p>
          <p class="profile-bio">热爱技术，专注于前端开发和用户体验设计。喜欢探索新技术，分享知识和经验。</p>
          <div class="profile-social">
            <a href="#" class="social-link">GitHub</a>
            <a href="#" class="social-link">Twitter</a>
            <a href="#" class="social-link">LinkedIn</a>
          </div>
        </div>
      </div>
      
      <div class="profile-content">
        <div class="profile-section">
          <h2 class="section-title">技能</h2>
          <div class="skills-grid">
            <div class="skill-item" v-for="skill in skills" :key="skill.name">
              <h3 class="skill-name" v-text="skill.name"></h3>
              <div class="skill-level">
                <div class="skill-bar">
                  <div class="skill-progress" :style="{ width: skill.level + '%' }"></div>
                </div>
                <span class="skill-percent"><span v-text="skill.level"></span>%</span>
              </div>
            </div>
          </div>
        </div>
        
        <div class="profile-section">
          <h2 class="section-title">最近文章</h2>
          <div class="posts-grid">
            <div 
              v-for="post in recentPosts" 
              :key="post.id" 
              class="post-card"
            >
              <div class="post-image" v-if="post.image">
                <img :src="post.image" :alt="post.title">
              </div>
              <div class="post-content">
                <div class="post-meta">
                  <span class="post-date" v-text="formatDate(post.date)"></span>
                </div>
                <h3 class="post-title">
                  <router-link :to="`/post/${post.id}`" v-text="post.title"></router-link>
                </h3>
                <p class="post-excerpt" v-text="post.excerpt"></p>
                <div class="post-tags">
                  <span 
                    v-for="tag in post.tags" 
                    :key="tag" 
                    class="tag"
                    v-text="tag"
                  >
                  </span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { allPosts } from '../utils/mock.js'

// 定义响应式数据
const skills = ref([
  { name: 'Vue.js', level: 95 },
  { name: 'JavaScript', level: 90 },
  { name: 'TypeScript', level: 85 },
  { name: 'CSS/SCSS', level: 85 },
  { name: 'React', level: 75 },
  { name: 'Node.js', level: 70 }
])

const recentPosts = ref(allPosts.slice(0, 3))

// 定义方法
function formatDate(dateString) {
  const options = { year: 'numeric', month: 'long', day: 'numeric' }
  return new Date(dateString).toLocaleDateString('zh-CN', options)
}
</script>

<style scoped>
.profile-page {
  width: 100%;
  padding: 2rem 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 2rem;
  margin-bottom: 3rem;
  padding: 2rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.profile-header:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.profile-avatar img {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  border: 5px solid #f0f2f5;
}

.profile-info {
  flex: 1;
}

.profile-name {
  font-size: 2rem;
  margin: 0 0 0.5rem 0;
  color: #333;
  position: relative;
}

.profile-name::after {
  content: '';
  display: block;
  width: 60px;
  height: 4px;
  background: linear-gradient(to right, #667eea, #764ba2);
  margin: 0.5rem 0;
  border-radius: 2px;
}

.profile-title {
  font-size: 1.2rem;
  color: #667eea;
  margin: 0 0 1rem 0;
  font-weight: 600;
}

.profile-bio {
  color: #666;
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.profile-social {
  display: flex;
  gap: 1rem;
}

.social-link {
  text-decoration: none;
  color: #667eea;
  padding: 0.5rem 1rem;
  border: 2px solid #667eea;
  border-radius: 30px;
  transition: all 0.3s;
  font-weight: 600;
}

.social-link:hover {
  background: linear-gradient(to right, #667eea, #764ba2);
  color: white;
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(102, 126, 234, 0.3);
}

.profile-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3rem;
}

.profile-section {
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: #333;
  position: relative;
  padding-bottom: 0.5rem;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 50px;
  height: 3px;
  background: linear-gradient(to right, #667eea, #764ba2);
  border-radius: 2px;
}

.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.skill-item {
  background: white;
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.skill-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.skill-name {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: #333;
  font-weight: 600;
}

.skill-level {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.skill-bar {
  flex: 1;
  height: 8px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
}

.skill-progress {
  height: 100%;
  background: linear-gradient(to right, #667eea, #764ba2);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.skill-percent {
  font-size: 0.9rem;
  color: #666;
  min-width: 40px;
  text-align: right;
  font-weight: 600;
}

.posts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
}

.post-card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.post-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.12);
}

.post-image img {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.post-content {
  padding: 1.5rem;
}

.post-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.post-date {
  font-size: 0.9rem;
  color: #666;
}

.post-title {
  margin: 0 0 1rem 0;
}

.post-title a {
  text-decoration: none;
  color: #333;
  font-size: 1.2rem;
  font-weight: 600;
  transition: color 0.3s;
  position: relative;
}

.post-title a::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(to right, #667eea, #764ba2);
  transition: width 0.3s ease;
}

.post-title a:hover {
  color: #667eea;
}

.post-title a:hover::after {
  width: 100%;
}

.post-excerpt {
  color: #666;
  line-height: 1.6;
  margin-bottom: 1rem;
}

.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  background: linear-gradient(to right, #f0f2f5, #e1e5ea);
  color: #555;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  transition: all 0.3s ease;
}

.tag:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
  .profile-header {
    flex-direction: column;
    text-align: center;
  }
  
  .profile-social {
    justify-content: center;
  }
  
  .skills-grid,
  .posts-grid {
    grid-template-columns: 1fr;
  }
}
</style>